﻿using Kingdee.BOS.App.Data;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading.Tasks;

namespace NS
{
    [HotUpdate]
    [Description("保存后基本信息1688辅助属性，把1688页签ID携带到基本信息")]
    public class _1688Services : AbstractOperationServicePlugIn
    {
        public override void OnPreparePropertys(Kingdee.BOS.Core.DynamicForm.PlugIn.Args.PreparePropertysEventArgs e)
        {
            e.FieldKeys.Add("FMATERIALID");
            base.OnPreparePropertys(e);
        }

        public override void AfterExecuteOperationTransaction(AfterExecuteOperationTransaction e)
        {
            base.AfterExecuteOperationTransaction(e);
            foreach (DynamicObject item in e.DataEntitys)
            {
                string FMATERIALID = "", F_WNEG_Text_apv = "", F_WNEG_TEXT22="", F_WNEG_TEXT23="";
                if (item["ID"] != null && Convert.ToString(item["ID"]) != "")
                {
                    FMATERIALID = Convert.ToString(item["ID"]);
                }
                string SQL = "/*dialect*/" + string.Format(@"select F_WNEG_Text_apv from T_BD_MATERIAL where FMATERIALID={0}", FMATERIALID);
                DynamicObjectCollection DynamData = DBUtils.ExecuteDynamicObject(this.Context, SQL);
                if(DynamData.Count>0)
                {
                    F_WNEG_Text_apv = Convert.ToString(DynamData[0]["F_WNEG_Text_apv"]);
                }
                if(F_WNEG_Text_apv!="")
                {
                    string SQL0 = "/*dialect*/" + string.Format(@"select F_WNEG_TEXT22,F_WNEG_TEXT23 from WNEG_t_Cust_Entry100068 where FMATERIALID={0}", FMATERIALID);
                    DynamicObjectCollection DynamData0 = DBUtils.ExecuteDynamicObject(this.Context, SQL0);
                    if(DynamData0.Count>0)
                    {
                        for(int i=0;i<DynamData0.Count;i++)
                        {
                            F_WNEG_TEXT22 = Convert.ToString(DynamData0[i]["F_WNEG_TEXT22"]);
                            F_WNEG_TEXT23 = Convert.ToString(DynamData0[i]["F_WNEG_TEXT23"]);
                            if(F_WNEG_TEXT22== F_WNEG_Text_apv)
                            {
                                string SQL1 = "/*dialect*/" + string.Format(@"UPDATE T_BD_MATERIAL SET F_WNEG_TEXT21='{1}' where FMATERIALID={0}", FMATERIALID, F_WNEG_TEXT23);
                                DBUtils.ExecuteDynamicObject(this.Context, SQL1);
                            }
                        }
                    }
                }
            }
        }
    }
}
